﻿using System.Data;

namespace ChargeManagement.DAL
{   
    public class CashAcceptType
    {
        public static DataSet GetCashAcceptType()
        { 
            //read configurations from xml file to DataSet 
            string xmlFile = "CashAcceptType.xml";

            DataSet ds = new DataSet();
            ds.ReadXml(xmlFile);
            return ds;
        }

        //得到现金收取类型列表，返回字符串数组
        public static string[] GetCashAcceptTypeList()
        {
            DataSet ds = CashAcceptType.GetCashAcceptType();
            int rowCount = ds.Tables[0].DefaultView.Count;
            string[] arrarResult = new string[rowCount];
            for (int i = 0; i < rowCount; i++)
            {
                arrarResult[i] = (string)ds.Tables[0].DefaultView[i]["name"];
            }
            return arrarResult;
        }

        /// <summary>
        /// Get paras based on the type of algorithm
        /// </summary>
        /// <param name="selectValue"></param>
        /// <returns></returns>
        public static object[] GetAlgorithmArgs(string selectValue)
        {
            DataSet ds = CashAcceptType.GetCashAcceptType();
            DataRow dr;
            object[] args = null;

            dr = ((DataRow[])ds.Tables[0].Select("name='" + selectValue + "'"))[0];

            if (dr["para"].ToString() != "")
                args = dr["para"].ToString().Split(',');

            return args;
        }

        public static string GetAlgorithmClass(string selectValue)
        {
            DataSet ds = CashAcceptType.GetCashAcceptType();
            DataRow dr;            

            dr = ((DataRow[])ds.Tables[0].Select("name='" + selectValue + "'"))[0];

            return dr["class"].ToString();
        }
    }
}
